import ctypes
import os
import time

import cv2
import numpy as np

libLoad = ctypes.cdll.LoadLibrary
sharelib = libLoad("./build/libpython_share_memory.so")

def get_img():
    sharelib.get_img.restype =ctypes.POINTER(ctypes.c_uint8)  #c_char_p
    pointer_img = sharelib.get_img()
    size=(480,640,3)
    RecImg =  np.reshape(np.array(np.fromiter(pointer_img, dtype=np.uint8, count=size[0]*size[1]*size[2])) ,size)
    return RecImg
 
def get_img_flag():
    sharelib.get_img_flag.restype = ctypes.c_int
    return sharelib.get_img_flag()

def get_pc_flag():
    sharelib.get_pc_flag.restype = ctypes.c_int
    return sharelib.get_pc_flag()


print("condinst ok!")
while True:

    time.sleep(0.0001)#防止绝对的空循环导致CPu占用，其他进程无法修改共享内存

    if(get_img_flag()==1 and get_pc_flag()==2 ):
        a=0
        for i in range(500000):
            a = 1+a
            print("a ", a)
        Py_img=get_img()
        # print("img shape", Py_img.shape)
        # cv2.imshow("showimg1 ", Py_img)
        # cv2.waitKey(0)
    
    # if(get_img_flag()==2):




